package com.sne.airways.route.controller;

import com.sne.airways.basecore.controller.BaseController;
import com.sne.airways.route.pojo.ExpAirPort;
import com.sne.airways.route.pojo.ExpCountry;
import com.sne.airways.route.service.ConPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 卞京帅{bjslogin@gmail.com}
 * Date: 12-11-20
 * Time: 下午10:51
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/port")
public class ConPortController extends BaseController {

    @Autowired
    private ConPortService conPortService;

    @RequestMapping("/getCountry")
    @ResponseBody
    public void initOperation(Integer start,Integer limit,String countryName,String countryCode){
        List<ExpCountry> list = conPortService.getCountry(
                start,limit,
                "countryName","like",countryName,
                "countryCode","like",countryCode
        );
        Integer count = conPortService.getCountryCount(
                "countryName","like",countryName,
                "countryCode","like",countryCode
        );
        renderPageJsonArray(list,new String[]{"createUser","portSet","modifyUser"},count);
    }

    @RequestMapping("/getAirPort")
    @ResponseBody
    public void getAirPort(Integer start,Integer limit,String portName,String portCode){
        List<ExpAirPort> list = conPortService.getAirPort(
                start,limit,
                "portName","like",portName,
                "portCode","like",portCode
        );
        Integer count = conPortService.getAirPortCount(
                "portCode","like",portCode,
                "portCode","like",portCode
        );
        renderPageJsonArray(list,new String[]{"country","createUser","modifyUser"},count);
    }

    @RequestMapping("/saveCountry")
    @ResponseBody
    public void saveCountry(String data){
        conPortService.saveCountry(data);
        renderSuccess();
    }


    @RequestMapping("/savePort")
    @ResponseBody
    public void savePort(String data){
        conPortService.savePort(data);
        renderSuccess();
    }
}
